package com.zs.proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/6/10 下午10:50
 */
public class IntermediaryMethodInterceptor2 implements MethodInterceptor {

    /**
     * @param o
     * @param method
     * @param objects
     * @param methodProxy
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        //执行日志操作
        System.out.println("[日志] 调用方法: " + method.getName() + ", 参数: " + Arrays.toString(objects) + "开始时间：" + new Date(System.currentTimeMillis()));
        Object result = methodProxy.invokeSuper(o, objects);
        //执行日志操作
        System.out.println("[日志] 调用方法: " + method.getName() + ", 参数: " + Arrays.toString(objects) + "执行完成，结束时间：" + new Date(System.currentTimeMillis()));
        return result;
    }
}
